package svc.elib.analysis;

import java.io.IOException;
import java.util.Iterator;

import svc.elib.db.Database;
import svc.elib.socnet.EvolutionarySnapshots;
import svc.elib.socnet.Link;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class WeightEvolution {
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		System.out.println(db.info());
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		net.printInfo();
		
		EvolutionarySnapshots es = new EvolutionarySnapshots(net);
		int startYear = es.getStartYear();
		Net[] snaps = es.getSnapshots();
		
		int numSnaps = snaps.length;
		for (int i = 0; i < numSnaps; i++) {
			Net snap = snaps[i];
			int year = startYear + i;
			
			double sum = 0.0;
			double num = 0.0;
			Iterator<Link> it = snap.getGraph().getEdges().iterator();
			while (it.hasNext()) {
				Link l = it.next();
				sum += l.getWeight();
				num += 1.0;
			}
			
			double avg = (double) sum / (double) num;
			System.out.println(year + ", " + avg);
		}
	}

}
